<template>
  <div style="box">
    <template>
      <i class="el-icon-user" style="color: orange; font-size: 22px">
        <span style="font-size: 18px; color: #ccc">用户管理列表</span>
      </i>
    </template>

    <div style="text-align: center; margin-bottom: 25px">
      <el-input
        placeholder="请输入用户名进行查询"
        clearable
        v-model="selectId"
        style="width: 250px; margin-right: 25px"
      >
      </el-input>
      <el-button plain @click="all">查询</el-button>
    </div>
    <template>
      <div style="text-align: center; margin-buttom: 10px">
        <el-button size="medium " type="danger" @click="handleDelete">删除</el-button>
      </div>
    </template>
    <!-- 全选 -->
    <el-table :data="qwe" @selection-change="check" style="width: 80%; margin: auto" height="410px">
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="用户名" width="220">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>账号: {{ scope.row.username }}</p>
            <p>密码: {{ scope.row.password }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.username }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="密码" width="220">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>姓名: {{ scope.row.username }}</p>
            <p>密码: {{ scope.row.password }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.password }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template v-slot:default="scope">
          <el-button size="mini" @click="edit(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <template>
      <el-dialog title="修改用户信息" :visible.sync="dialogFormVisible">
        <el-form>
          <el-form-item label="修改的用户名">
            <el-input autocomplete="off" v-model="modification.username"></el-input>
          </el-form-item>
        </el-form>
        <el-form>
          <el-form-item label="修改的密码">
            <el-input autocomplete="off" v-model="modification.password"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="alter">确 定</el-button>
          <!-- {{selectId}} -->
        </div>
      </el-dialog>
    </template>
  </div>
</template>

<script>
// import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'
export default {
  name: "UserList",
  data() {
    return {
      selectId: "",
      dialogFormVisible: false,
      modification: {
        id: "",
        username: "",
        password: "",
      },
    };
  },
  created() {
    this.$store.dispatch("getData");
  },
  mounted() {
    console.log(this);
  },
  watch: {},

  methods: {
    handleDelete() {
      this.$store.dispatch("handleDelete");
    },
    all() {
      console.log(this.selectId);
      if (this.$store.dispatch("all", this.selectId)) {
        // console.log('78978');
      }
    },
    check(a) {
      // console.log(a);
      this.$store.commit("check", a);
    },
    edit(a) {
      this.modification.id = a.id;
      this.modification.username = a.username;
      this.dialogFormVisible = true;
      // this.$store.dispatch('edit',a)
    },
    alter() {
      console.log(this.modification);
      this.$store.dispatch("alter", this.modification);
      this.dialogFormVisible = false;
    },
  },
  computed: {
    qwe() {
      console.log(this.$store.state);
      console.log();
      return this.$store.state.administrator.datas;
    },
  },
};
</script>
<style scoped>
/* a{
  margin: auto
} */
</style>
